<script type="text/javascript" language="javascript" charset="utf-8">
$(".menu-wrap li").removeClass("active-link");
$(".menu-wrap #goods").addClass("active");
$("#goods #info").addClass("active-link");
$("#goods #good_list a").addClass("active-link");
</script>
<div class="common-tit">
  <h2>商品列表</h2>
  <span>商品管理 > 商品列表</span>
  <%= link_to '添加商品', new_admin_good_path, class: "add-staff"%>
</div>
<div class="cur-list">
  <div class="cur-listbox clearfix">
    <div class="cur-ll clearfix">
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">商品分类</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">商品分类</li>
          <li data_id="课程商品">课程商品</li>
          <li data_id="周边商品">周边商品</li>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">商品类型</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">商品类型</li>
          <% @sale_courses.each do |sale| %>
            <li data_id="<%= sale.id %>"><%= sale.name %></li>
          <% end %>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="">排序</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="price asc">价格由低到高</li>
          <li data_id="price desc">价格由高到低</li>
          <li data_id="sale_amount asc">销量由低到高</li>
          <li data_id="sale_amount desc">销量由高到低</li>
        </ul>
      </div>
    </div>
  </div>
  <div class="curlist-con">
    <%= render partial: "table" %>
  </div>
</div>
<script src="/assets/js/common.js"></script>
<script>
$(".cur-ll .list-box li").on("click", function() {
  $(this).parent().parent().find("span").attr("data_id", $(this).attr("data_id"));
  transData();
});
function transData() {
  var transD = "";
  transD += "view_type=table&";
  for (var i = 0; i < $(".cur-ll .list-box").length; i++) {
    switch(true) {
      case i == 0: transD += "good_type" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 1: transD += "good_info_id" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 2: transD += "sort" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id");break;
    };
  };
  console.log(transD);
  $.ajax({
    type:'get', url:"/admin/goods/get_good_list?"+ transD,
    success: function(data) {
      if (data.error) {
        // console.log("wrong");
      }
    }
  });
};
</script>
